package com.lms.time;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.chrono.Era;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-06-29 14:02
 * @Description:
 */
public class LocalDateDemo {
    public static void main(String[] args) {
        //+999999999-12-31
        LocalDate max = LocalDate.MAX;
        //-999999999-01-01
        LocalDate min = LocalDate.MIN;
        //2020-06-29
        LocalDate now = LocalDate.now();
        //从此日期获取指定字段的 int 。 6
        int i = now.get(ChronoField.MONTH_OF_YEAR);
        //JUNE
        Month month = now.getMonth();
        //从此日期获取指定字段的值为 long 。 6
        long aLong = now.getLong(ChronoField.MONTH_OF_YEAR);
        //MONDAY
        DayOfWeek dayOfWeek = now.getDayOfWeek();
        Era era = now.getEra();
        //加两天
        LocalDate localDate = now.plusDays(2);
        //减去三月
        LocalDate localDate1 = now.minusMonths(3);
        //减去两年
        LocalDate minus = now.minus(2, ChronoUnit.YEARS);
        //2022-06-29
        LocalDate localDate2 = now.withYear(2022);
        //返回此日期的副本，并将指定的字段设置为新值。
        LocalDate with = now.with(ChronoField.MONTH_OF_YEAR, 7);
        //2019-08-20
        LocalDate of = LocalDate.of(2019, 8, 20);
        LocalDate of1 = LocalDate.of(2019, Month.AUGUST, 20);
        //这将返回一个LocalDate与指定的时代。 EPOCH_DAY是第0天为1970-01-01的简单递增计数。 负数表示较早的日子。1970-01-02
        LocalDate localDate3 = LocalDate.ofEpochDay(1);
        //从一个文本字符串（如 2007-12-03获取一个 LocalDate的实例。
        LocalDate parse = LocalDate.parse("2007-12-03");
        //使用特定的模式解析字符串为日期。
        LocalDate parse1 = LocalDate.parse("2020-8-17", DateTimeFormatter.ofPattern("yyyy-M-dd"));
        //366 返回一年的天数
        int i1 = now.lengthOfYear();
        //30,一月中的天数
        int i2 = now.lengthOfMonth();
        //将此日期与午夜时间结合 LocalDateTime ，在此日期开始时创建一个 LocalDateTime 。 2020-06-29T00:00
        LocalDateTime localDateTime = now.atStartOfDay();
        //结合此日期与时间创建一个 LocalDateTime 。 2020-06-29T15:21:10
        LocalDateTime localDateTime1 = now.atTime(15, 21, 10);
        //2020/06/29
        String format = now.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));

    }
}
